#!usr/bin/python
# -*- coding: utf-8 -*-

import numpy as np
import os

import datetime
# 关闭tensorflow警告
import time
import MySQLdb
import argparse
import sys
reload(sys)
sys.setdefaultencoding('utf8')


def query_from_database():
    conn=MySQLdb.connect(user='root',passwd='liuyanjie',host='49.234.81.253',port=3306,db='rdshare',charset='utf8')
    cursor = conn.cursor()

    #查询目标检测状态表，查看frame_num是否已经被检测过，若是，则更新，若否，则插入
    sql="SELECT * FROM MFwanzheng WHERE id >0 and id < 30842 ";
    cursor.execute(sql)
    results = cursor.fetchall()
    origin_frame=''
    false_num=0
    all_num=0
    tp=0
    fp=0
    fn=0
    if(results):
        for row in results:
            id=row[1]
            objects=row[2]
            #print()
            if(int(row[1])%2==0):
                #print(objects)
                origin_frame=objects.strip()
                tp=tp+len(origin_frame)
            else:
                now_frame=objects.strip()
                #all_num=all_num+len(now_frame)
                #if(not(origin_frame == now_frame)):
                    #false_num=false_num+1
                    #print(origin_frame)
                    #print(now_frame)
                for i in range(0,len(origin_frame)):
                    if(not(origin_frame[i] in now_frame)):  #检测到有，但没有
                        fn=fn+1
                    else:
                    	tp=tp+1
                for i in range(0,len(now_frame)):
                    if(not(now_frame[i] in origin_frame)):  #检测到有，但没有
                        fp=fp+1
        print("tp: ", tp)
        print("fn: ", fn)
        print("fp: ", fp)
        #print("all_num: ", all_num)

        
    print(false_num)
    cursor.close()


if __name__ == '__main__':
# 运行
    start = time.time()
    query_from_database()
    end = time.time()
    print('time:\n')
    print str(end-start)

